package Task25;

import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            String s = sc.nextLine();
            while(s.length() > 1){
                char[] ch = s.toCharArray();
                int num = 0;
                for(int i = 0;i < ch.length;i++){
                    num += ch[i] - '0';
                }
                s = String.valueOf(num);
            }
            System.out.println(s);
        }
    }
}
